<template>
  <div id="itrn" v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig" :tableSelectData="tableSelectData" :title="$t('ex.itrn_tran')" @exportFile="exportFile">
    </v-tableTitle>
    <v-table :page="page" :pageSize="pageSize" :tableConfig="tableConfig" :tableData="tableData" :total="total"
      @findData="getTableData" @getTableData="getTableData" @searhData="searhData" @selectData="selectData"
      @setdialog="setdialog" @upData="getTableData" ref="table"></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";

export default {
  name: "itrn",
  mixins: [baseMixin],
  data() {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('ex.itrnkeycode'),
          prop: "itrnkey",
          input: "input",
        },
        {
          label: this.$t('out.orderno'),
          prop: "sourcekey",
          input: "input",
          width: "100px"
        },
        {
          label: this.$t('common.date'),
          prop: "effectivedatestr",
          input: "input",
          width: "100px"
        },
        {
          label: this.$t('bill.activity'),
          prop: "trantype",
          input: "select",
          options: this.getOptions("querycodeLkup/ITRNTYPE")
        },
        {
          label: this.$t('config.shipper'),
          prop: "storerkey",
          input: "input",
        },
        {
          label: this.$t('config.sku'),
          prop: "sku",
          input: "input"
        },
        {
          label: this.$t('in.lot'),
          prop: "lot",
          input: "input"
        },
        {
          label: this.$t('config.toLoc'),
          prop: "toloc",
          input: "input"
        },
        {
          label: this.$t('in.toid'),
          prop: "toid",
          input: "input"
        },
        {
          label: this.$t('outbound.fromloc'),
          prop: "fromloc",
          input: "input"
        },
        {
          label: this.$t('in.fromid'),
          prop: "fromid",
          input: "input"
        },
        {
          label: this.$t('config.num'),
          prop: "qty",
          input: "input"
        },
        {
          label: this.$t('outbound.user'),
          prop: "addwho",
          input: "input"
        },
        {
          label: this.$t('config.gross'),
          prop: "grosswgt",
          input: "input"
        },
        {
          label: this.$t('config.suttle'),
          prop: "netwgt",
          input: "input"
        },
        {
          label: this.$t('config.tareWeight'),
          prop: "tarewgt",
          input: "input"
        },
        {
          label: this.$t('config.batchProp',{no:'01'}),
          prop: "lottable01",
          input: "input"
        },
        {
          label: this.$t('config.batchProp',{no:'02'}),
          prop: "lottable02",
          input: "input"
        },
        {
          label: this.$t('config.batchProp',{no:'03'}),
          prop: "lottable03",
          input: "input"
        },
        {
          label: this.$t('in.lottable04'),
          prop: "lottable04",
          input: "date"
        },
        {
          label: this.$t('in.lottable05'),
          prop: "lottable05",
          input: "date"
        },
        {
          label: this.$t('config.batchProp',{no:'06'}),
          prop: "lottable06",
          input: "input"
        },
        {
          label: this.$t('config.batchProp',{no:'07'}),
          prop: "lottable07",
          input: "input"
        },
        {
          label: this.$t('config.batchProp',{no:'08'}),
          prop: "lottable08",
          input: "input"
        },
        {
          label: this.$t('config.batchProp',{no:'09'}),
          prop: "lottable09",
          input: "input"
        },
        {
          label: this.$t('config.batchProp',{no:'10'}),
          prop: "lottable10",
          input: "input"
        },
        {
          label: this.$t('ex.lottable11'),
          prop: "lottable11",
          input: "date"
        },
        {
          label: this.$t('in.lottable12'),
          prop: "lottable12",
          input: "date"
        },
      ],
      tableData: [],
      pageSize: 10,
      page: 1,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
    };
  },
  computed: {
    btnConfig() {
      return [
        { label: this.$t('common.export'), certigier: !this.btnPermNameList.includes('WM06020201'), disabled: true, invalid: "exportFile" },
      ]
    }
  },
  created() {
  },
  methods: {
    //导出
    async exportFile(data) {
      try {
        let res = await this.$api.post('/exportItrn', data, { responseType: 'blob' })
        if (window.navigator.msSaveBlob) {
          var blobObject = new Blob([res.data]);
          window.navigator.msSaveBlob(blobObject, this.$t('ex.itrn_tran') + '.xls');
        } else {
          var blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8' });
          var filename = this.$t('ex.itrn_tran') + '.xls';
          var downloadElement = document.createElement('a');
          var href = window.URL.createObjectURL(blob); //创建下载的链接
          downloadElement.style.display = 'none';
          downloadElement.href = href;
          downloadElement.download = filename; //下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); //点击下载
          document.body.removeChild(downloadElement); //下载完成移除元素
          window.URL.revokeObjectURL(href); //释放掉blob对象
        }
      } catch (e) {
        this.$message.error(e);
      } finally {
        
      }
    },
    //选中的内容
    selectData(data) {
      this.tableSelectData = data;
    },
    async getTableData(page, data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/queryItrn/${page}`, data);
        
          this.tableData = res.page.list;
          this.page = res.page.curPage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    },
    //搜索的值
    searhData(data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
    //设置弹框
    setdialog(data) {
      this.$store.commit("setRouteData", data);
      this.$router.push({ name: 'itrnDeawer' });
    },
  },
  mounted() {
    this.$store.commit("setSkip", {});
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    this.getTableData(1, {});
  },
  watch: {},
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
  }
};
</script>

<style scoped>
#itrn {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
